package Week3.num.week3Test1.solar;

/**
 * 太阳系行星类型
 */
public class Planet extends AbstrectSolarObject{
    /**
     * 行星的序号
     */
    String no;
    /**
     * 行星的名字
     */
    String name;

    int longAxis;

    int shortAxis;

    double theta;

    public Planet() {
    }
    public Planet(String no, String name,double au,double e,int t){
        this.no=no;
        this.name=name;
        this.longAxis=getLongAxisByAu(au);
        this.shortAxis=getShortAxisByE(e);
        this.theta=0.0;
        this.speed=getSpeedByT(t);
    }

    @Override
    public void move() {
        x=(int) (longAxis*Math.cos(theta));
        y=(int) (shortAxis*Math.cos(theta));
        theta+=speed;
        System.out.println("地球的x坐标:"+this.x);
        System.out.println("地球的y坐标:"+this.y);
    }

    @Override
    public void draw() {
        super.draw();
    }

    private int getLongAxisByAu(double au){
        return (int)(au*Constant.RATE);
    }

    private int getShortAxisByE(double e){
        return (int)(longAxis*Math.sqrt(1-Math.pow(e,2)));
    }

    /**
     *
     * @param t 行星公转周期
     * @return 单位时间线速度方向的改变量
     */
    private double getSpeedByT(int t){
        return 365/t*0.1;
    }

    public void run(){
        while (true){
            move();
        }
    }
}
